package com.cqh.recruit.controller.school;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqh.recruit.pojo.dto.MFeedQueryDto;
import com.cqh.recruit.pojo.entity.Feedback;
import com.cqh.recruit.pojo.vo.MFeedListVo;
import com.cqh.recruit.result.Result;
import com.cqh.recruit.service.IFeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 *
 *  前端控制器
 *
 *
 * @author dh
 * @since 2025-10-18
 * @version v1.0
 */
@RestController("schoolFeedbackController")
@RequestMapping("/api/school/feedback")
public class FeedbackController {

    @Autowired
    private IFeedbackService feedbackService;

    @GetMapping("/find")
    @Operation(summary = "根据id查询反馈")
    public Result find(Long id) {
        if (id == null) {
            return Result.buildFail(2001, "id不能为空");
        }
        MFeedListVo feedback = feedbackService.findFeedById(id);
        return Result.buildSuccess(feedback);
    }

    @PostMapping("/add")
    @Operation(summary = "添加反馈")
    public Result add(@RequestBody Feedback  feedback) {
        feedback.setCreateTime(LocalDateTime.now());
        feedbackService.save(feedback);
        return Result.buildSuccess();
    }
    @PostMapping("/update")
    @Operation(summary = "更新反馈")
    public Result update(@RequestBody Feedback feedback) {
        feedback.setUpdateTime(LocalDateTime.now());
        feedbackService.updateById(feedback);
        return Result.buildSuccess();
    }
    @GetMapping("/delete")
    @Operation(summary = "删除反馈")
    public Result delete(Long id) {
        if (id == null) {
            return Result.buildFail(2001, "id不能为空");
        }
        feedbackService.removeById(id);
        return Result.buildSuccess();
    }
    @PostMapping("/list")
    @Operation(summary = "查询反馈列表")
    public Result list(@RequestBody MFeedQueryDto feedbackQueryDto) {
        Page<MFeedListVo> resultPage = feedbackService.findFeedByQueryDto(feedbackQueryDto);
        return Result.buildSuccess(resultPage.getRecords(), resultPage.getTotal());
    }
}

